<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/common/taglibs.jsp" %>
<%@ taglib prefix ="s" uri="/struts-tags"%>
<%@ page import="com.starbaba.core.web.constant.WebConstants"%>
<%@ page import="com.starbaba.system.user.model.UserVO"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
	<head>
		<%@ include file="/common/common-css.v2.jsp" %>
		
		<style>
		#jquery-table td{word-break: break-all;word-wrap: break-word;}
		.load_bg{background:#000;opacity:0.1;left:0px;top:0px;position:fixed;height:100%;width:100%;overflow:hidden;z-index:10000;}
		.load_img{left:50%;top:180px;position:fixed;height:50px;overflow:hidden;z-index:20000;}
		a.check{
			margin-bottom:10px;
		}
		.discovery-alert {
		    position: fixed;
		    width: 300px;
		    z-index: 99999;
		    left: 50%;
		    margin-left: -150px;
		    top: 300px;
		    display: none;
		}
		
		.dd { position: relative; display: block; margin: 0; padding: 0; list-style: none; font-size: 13px; line-height: 20px;max-width: 1000px; }

		.dd-list { display: block; position: relative; margin: 0; padding: 0; list-style: none; }
		.dd-list .dd-list { padding-left: 30px; }
		.dd-collapsed .dd-list { display: none; }

		.dd-item,
		.dd-empty,
		.dd-placeholder { display: block; position: relative; margin: 0; padding: 0; min-height: 20px; font-size: 13px; line-height: 20px; }

		.dd-handle { display: block; margin: 5px 0; padding: 8px 10px 8px 30px; min-height: auto; color: #333; text-decoration: none; font-weight: bold; border: 1px solid #ccc;
			background: #fafafa;
			-webkit-border-radius: 3px;
			border-radius: 3px;
			box-sizing: border-box; -moz-box-sizing: border-box;
			position: relative;
		}
		.dd-handle span.menu-icon{
		    position: absolute;
		    top: 12px;
		    left: 8px;
		    cursor: pointer;
		}
		.dd-handle span.opera-icon {
		    right: 10px;
		    left: inherit;
		}
		.dd-handle span.opera-icon-single{
			right: 40px;
		}
		
		#nestable .dd-handle{
			background: #669fc7;
			color: #ffffff;
		}
		#nestable .dd-handle span.menu-icon{
			color: #ffffff;
		}

		.dd-item > button { display: block; position: relative; cursor: pointer; float: left; width: 25px; height: 20px; margin: 5px 0; padding: 0; text-indent: 100%; white-space: nowrap; overflow: hidden; border: 0; background: transparent; font-size: 12px; line-height: 1; text-align: center; font-weight: bold; }
		.dd-item > button:before { content: '+'; display: block; position: absolute; width: 100%; text-align: center; text-indent: 0; }
		.dd-item > button[data-action="collapse"]:before { content: '-'; }

		.dd-placeholder,
		.dd-empty { margin: 5px 0; padding: 0; min-height: 30px; background: #f2fbff; border: 1px dashed #b6bcbf; box-sizing: border-box; -moz-box-sizing: border-box; }
		.dd-empty { border: 1px dashed #bbb; min-height: 100px; background-color: #e5e5e5;
			background-image: -webkit-linear-gradient(45deg, #fff 25%, transparent 25%, transparent 75%, #fff 75%, #fff),
							  -webkit-linear-gradient(45deg, #fff 25%, transparent 25%, transparent 75%, #fff 75%, #fff);
			background-image:    -moz-linear-gradient(45deg, #fff 25%, transparent 25%, transparent 75%, #fff 75%, #fff),
								 -moz-linear-gradient(45deg, #fff 25%, transparent 25%, transparent 75%, #fff 75%, #fff);
			background-image:         linear-gradient(45deg, #fff 25%, transparent 25%, transparent 75%, #fff 75%, #fff),
									  linear-gradient(45deg, #fff 25%, transparent 25%, transparent 75%, #fff 75%, #fff);
			background-size: 60px 60px;
			background-position: 0 0, 30px 30px;
		}

		.dd-dragel { position: absolute; pointer-events: none; z-index: 9999; }
		.dd-dragel > .dd-item .dd-handle { margin-top: 0; }
		.dd-dragel .dd-handle {
			-webkit-box-shadow: 2px 4px 6px 0 rgba(0,0,0,.1);
					box-shadow: 2px 4px 6px 0 rgba(0,0,0,.1);
		}
		.setnone{
			display: none;
		}
		</style>
	</head>
<body  class="no-skin">
<div  class="load_bg" style="display:none;" ></div>
<img src="http://img.xmiles.cn/commentloading.gif" class="load_img" style="display:none"/>
<div class="page-content">
<div id="test"></div>
			<div class="page-header" style="margin-bottom:0px;padding-bottom:10px;">
			
				<h1 id="fu_name">
					
				</h1>
			</div>
	<div class="page-content-area">
		<div class="row">
			<div class="col-sm-12">
				<div class="widget-box" style="border:0px solid #ccc; border-top:none;border-bottom:none;">
					<div class="widget-header widget-header-blue widget-header-flat">
						<h4 class="widget-title">选择条件进行操作</h4>

						<div class="widget-toolbar">
							<a href="#" data-action="collapse">
								<i class="ace-icon fa fa-chevron-up"></i>
							</a>
						</div>
					</div>

					<div class=" widget-body">
						<!-- <div class="widget-main" style="padding:12px;border:0px solid #ccc; border-top:none;border-bottom:none;"> -->
									<div class="widget-main clearfix" >

										<div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-4">
											<label class="col-sm-2 control-label" for="user" style="text-align:right;">组别:</label>
											<div class="col-sm-10">
												<select class="form-control" name="user" id="user">
												</select>
											</div>
										</div>
										
										<div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-4 center">
											<button class="btn btn-primary" data-toggle="modal" data-target="#myModal">新增组</button>
										</div>
										
										
							</div><!-- /.widget-main -->
					</div><!-- /.widget-body -->
				</div><!-- /.widget-box -->
			</div><!-- /.col-sm-12 -->
		</div><!-- /.row -->
		
		<div class="row">
			<div class="col-xs-12">
				<!--菜单展示-->
				<div class="cf nestable-lists clearfix">
					<div class="dd col-sm-5" id="nestable">
					    
					</div>
					<div class="col-sm-1">
					    <!--伪盒-->
					</div>
					<div class="dd col-sm-5" id="nestable2">
					    <div class="nestable-title hidden center" style="margin-bottom:20px;">
				           <button class="btn btn-sm" type="button" disabled="disabled">可添加权限</button>
						</div>
					</div>

				</div>
				
				
			</div><!-- /.col -->
		</div><!-- /.row -->
			
	</div><!-- /.page-content-area -->
</div><!-- /.page-content -->

<!--模态框-->
<div class="modal fade" id="myModal">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">新增组</h4>
      </div>
      <div class="modal-body clearfix">
	    <div class="row">
			<div class="form-group col-xs-10">
				<label class="col-sm-4 control-label"  for="group-name">组名:</label>
				<div class="input-group col-sm-8">
					<input type="text" class="form-control" name="group-name" id="group-name">
				</div>
			</div>
		</div>		
       	   
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
        <button type="button" class="btn btn-primary" id="addGroup">确认</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<!--警告-->
<div class="alert alert-danger alert-dismissible discovery-alert" role="alert">
  <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
  <span id="alert-text"></span>
</div>

<!--获取userid-->
<div id="getCreator" class="hidden"><cx:Code2Name definition="!com.starbaba.system.user.model.UserVO*username*userid" value="<%= ((UserVO) session.getAttribute(WebConstants.SESSION_ATTRIBUTE_USER)).getUserid() %>"/></div>
<div id="allMenuList" class="hidden"></div>

<%@ include file="/common/common-js.jsp" %>
<script type="text/javascript" src="${ctx}/js/call_func.js"></script>
<!-- inline scripts related to this page -->
<script type="text/javascript">
//定义参数
var limitedMenuList = [],
    allMenuList = [],
    controlingMenuListArr = [],
    limitedMenuListArr = [];
var userid = '';
var postGroupid = '';

var limitedFirstMenuList = [],
    limitedSecondMenuList = []
    limitedThirdMenuList = [];
    
var allMenuListTemp = null;    

var creator = $('#getCreator').text();

//接受URL参数，进行文档写入
function getQueryString(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
	var r = window.location.search.substr(1).match(reg);
	if (r != null) return decodeURI(r[2]); return null;
};

//提示
function toast(text, selector){
	$('#alert-text').text(text);
	$('.discovery-alert').show();
	if(selector != '' && selector != null){
		$(selector).focus();
	};
	setTimeout(function(){
		$('.discovery-alert').hide();
	},3000);
};
	
jQuery(function($) {
	//时间控件
	$(".date-picker").datepicker({autoclose:true}).next().on(ace.click_event, function(){
		$(this).prev().focus();
	});
	
	//请求组列表
	requestGroupList();
	
	//请求获取全部列表
	$.ajax({
		"type": "POST",
		"dataType": 'json',
		"url": ctx+"/system/userofrole/getList.action?type=1",
		"data": {},
		"beforeSend": function(){
			$(".load_bg,.load_img").show();
		},
		"success": function(resp){
            $('#allMenuList').html(resp);	
			var object;
			if(typeof(resp) == "string"){
			   object = $.parseJSON(resp);
			};
			console.log("全部菜单:" , object);
			allMenuList = object; 		
		},
		"error": function(XMLHttpRequest, textStatus, errorThrown) {
			alert(textStatus);
		},
		"complete": function(){
			$(".load_bg,.load_img").hide();
		}
	});
	
	//触发时获取userGroup
	$('#user').on('change',function(){
		//定义一个临时的储存allMenuList的数组(allMenuList第二次用时会被清空)
		allMenuListTemp = $.parseJSON($('#allMenuList').html());
		var groupid = $(this).val();
		postGroupid = groupid;
		if(groupid != '' && groupid != null){
		    //显示内容
		    $('.nestable-lists').show();
			//对变量userid赋值
		    userid = $(this).children("option:selected").attr("data-userid");
			//显示title
			$('.nestable-title').removeClass('hidden');
		    //把容器内容赋空
		    $('#nestable,#nestable2').html('');
		    
		    getLimitedMenuList();
		}else{
			$('.nestable-lists').hide();
		};
	});
	
	//新增组
	//添加用户确认按钮
	$('#addGroup').on('click', function(){
		var groupName = $('#group-name').val();
		if(groupName == ''){
			toast('请输入组名称', '#group-name');
		}else{
			//请求新增组
			$.ajax({
				"type": "POST",
				"dataType": 'json',
				"url": ctx+"/system/usergroup/addGroup.action",
				"data": {"groupname":groupName, "creator": creator},
				"beforeSend": function(){
					$(".load_bg,.load_img").show();
				},
				"success": function(resp){
					console.log(JSON.stringify(resp));
					if(resp.result.status == 1){
						//刷新
						requestGroupList();
						$('#myModal').modal('hide');
					};
				},
				"error": function(XMLHttpRequest, textStatus, errorThrown){
					toast(textStatus,'');
				},
				"complete": function(){
					$(".load_bg,.load_img").hide();
				}
			});	
		}
		
		
	});
	
	//点击展开菜单事件
	$(document).delegate('.fa-list', 'click', function(){
		var ddHandle = $(this).parent('.dd-handle');
		var ddList = null;
		if(ddHandle.attr('data-grade') == 1){
			ddList = ddHandle.next('.dd-list-flag');
		}else if(ddHandle.attr('data-grade') == 2){
			ddList = ddHandle.parent('li').next('.dd-list-flag');
		}
		ddList.toggle();
	});
	
	//点击添加权限事件
	$(document).delegate('.opera-icon-add', 'click', function(){
		var $this = $(this);
		var grade = $this.parent('.dd-handle').attr('data-grade');
		var id = $this.parent('.dd-handle').parent('li').attr('data-id');
		var parentid = $this.parent('.dd-handle').parent('li').attr('data-parentid');
		var postAddListArr = [];
		//直接添加三级菜单
		if(grade == 3){
			//检测是否有本id下的二级菜单
			if(!hasElement(limitedSecondMenuList, parentid)){
				toast('请先添加父菜单');
				return false;
			}else if(hasElement(limitedThirdMenuList, id)){
				toast('已存在');
				return false;
			}else{
				//正常添加
				postAddListArr.push($this.parent('.dd-handle').parent('li').attr('data-id'));
			};
		}else if(grade == 2){
			//检测是否有本id下的一级菜单
			if(!hasElement(limitedFirstMenuList, parentid)){
				toast('请先添加父菜单');
				return false;
			}else if(hasElement(limitedSecondMenuList, id)){
				toast('已存在');
				return false;
			}else{
				//正常添加
				$this.parent('.dd-handle').parent('li').next('ol').find('li').each(function(){
					postAddListArr.push($(this).attr('data-id'));
				});
				postAddListArr.push($this.parent('.dd-handle').parent('li').attr('data-id'));
			};
		}else{
			//添加一级菜单
			if(hasElement(limitedFirstMenuList, id)){
				toast('已存在');
				return false;
			}else{
				//正常添加
				$this.parent('.dd-handle').parent('li').find('li').each(function(){
					postAddListArr.push($(this).attr('data-id'));
				});
				postAddListArr.push($this.parent('.dd-handle').parent('li').attr('data-id'));
			}
			
		};
		getPostList(postAddListArr.join('#'), 1);
	});
	
	//点击新增(单项)权限事件
	$(document).delegate('.opera-icon-delete-single', 'click', function(){
		var $this = $(this);
		var grade = $this.parent('.dd-handle').attr('data-grade');
		var id = $this.parent('.dd-handle').parent('li').attr('data-id');
		var parentid = $this.parent('.dd-handle').parent('li').attr('data-parentid');
		var postAddListArrStr = '';
		//直接添加三级菜单
		if(grade == 3){
			//检测是否有本id下的二级菜单
			if(!hasElement(limitedSecondMenuList, parentid)){
				toast('请先添加父菜单');
				return false;
			}else if(hasElement(limitedThirdMenuList, id)){
				toast('已存在');
				return false;
			}else{
				//正常添加
				postAddListArrStr = $this.parent('.dd-handle').parent('li').attr('data-id');
			};
		}else if(grade == 2){
			//检测是否有本id下的一级菜单
			if(!hasElement(limitedFirstMenuList, parentid)){
				toast('请先添加父菜单');
				return false;
			}else if(hasElement(limitedSecondMenuList, id)){
				toast('已存在');
				return false;
			}else{
				//正常添加
				postAddListArrStr = $this.parent('.dd-handle').parent('li').attr('data-id');
			};
		}else{
			//添加一级菜单
			if(hasElement(limitedFirstMenuList, id)){
				toast('已存在');
				return false;
			}else{
				//正常添加
				postAddListArrStr = $this.parent('.dd-handle').parent('li').attr('data-id');
			}
			
		};
		getPostList(postAddListArrStr, 1);
	});
	
	//点击删除(包括子项)权限事件
	$(document).delegate('.opera-icon-delete', 'click', function(){
		var $this = $(this);
		var grade = $this.parent('.dd-handle').attr('data-grade');
		var id = $this.parent('.dd-handle').parent('li').attr('data-id');
		var parentid = $this.parent('.dd-handle').parent('li').attr('data-parentid');
		var postAddListArr = [];
		//直接删除三级菜单
		if(grade == 3){
			postAddListArr.push($this.parent('.dd-handle').parent('li').attr('data-id'));
		}else if(grade == 2){
			//正常添加
			$this.parent('.dd-handle').parent('li').next('ol').find('li').each(function(){
				postAddListArr.push($(this).attr('data-id'));
			});
			postAddListArr.push($this.parent('.dd-handle').parent('li').attr('data-id'));
		}else{
			$this.parent('.dd-handle').parent('li').find('li').each(function(){
				postAddListArr.push($(this).attr('data-id'));
			});
			postAddListArr.push($this.parent('.dd-handle').parent('li').attr('data-id'));
		};
		getPostList(postAddListArr.join('#'), 0);
	});
	
});	

function requestGroupList(){
	$.ajax({
		"type": "POST",
		"dataType": 'json',
		"url": ctx+"/system/usergroup/userGroupList.action",
		//"data": {"type": "1"},
		"beforeSend": function(){
			$('#user').html('');
		},
		"success": function(resp){
			console.log("组列表:" , resp);	
			$('#user').append('<option value="">请选择组</option>');
			$.each(resp.aaData, function(index, item){
                $('#user').append('<option value=' + item.groupid + '>' + item.groupname + '</option>');
			})			
		},
		"error": function(XMLHttpRequest, textStatus, errorThrown) {
			alert(textStatus);
		}
	});
};

//请求菜单信息
//权限菜单
function getLimitedMenuList(){
	$.ajax({
		"type": "POST",
		"dataType": 'json',
		"url": ctx+"/system/userofrole/getList.action?type=0",
		"data": {"groupid": postGroupid},
		"beforeSend": function(){
			$(".load_bg,.load_img").show();
			//清除即将要操作的数组
			controlingMenuList = [];
			limitedMenuList = [];
			limitedFirstMenuList = [];
			limitedSecondMenuList = [];
			limitedThirdMenuList = [];
		},
		"success": function(resp){
			var object;
			if(typeof(resp) == "string"){
			   object = $.parseJSON(resp);
			};
			console.log("当前选择组拥有的权限:" , object);
			limitedMenuList = object;
			
			$.each(limitedMenuList.firstMenu, function(index, item){
				limitedMenuListArr.push(item.controlid);
				limitedFirstMenuList.push(item.controlid);
			});
			$.each(limitedMenuList.secondMenu, function(index, item){
				limitedMenuListArr.push(item.controlid);
				limitedSecondMenuList.push(item.controlid);
			});
			$.each(limitedMenuList.thirdMenu, function(index, item){
				limitedMenuListArr.push(item.controlid);
				limitedThirdMenuList.push(item.controlid);
			});
			
			//生成DOM
	        newDom(object, '现有权限', '#nestable', 1);		

            //成功返回权限菜单之后对比所有菜单,并插入(所有菜单-权限菜单)的数据	
            getRestMenuList(limitedMenuList, allMenuListTemp);		
		},
		"error": function(XMLHttpRequest, textStatus, errorThrown) {
			alert(textStatus);
		},
		"complete": function(){
			$(".load_bg,.load_img").hide();
		}
	});
};

//筛选得出剩余菜单
//先循环thirdMenu,向上执行
function getRestMenuList(childList, parentList){
	
	var restFirstMenuList = getNotSameJson(parentList.firstMenu, childList.firstMenu);
	var restSecondMenuList = getNotSameJson(parentList.secondMenu, childList.secondMenu);
	var restThirdMenuList = getNotSameJson(parentList.thirdMenu, childList.thirdMenu);
	
	/*var restMenuList = [];
	restMenuList.concat(restFirstMenuList, restSecondMenuList, restThirdMenuList);*/
	
	//手动拼接为json数组
	var temp = '{"firstMenu": ' + JSON.stringify(restFirstMenuList) + ', "secondMenu": ' + JSON.stringify(restSecondMenuList) + ', "thirdMenu": ' + JSON.stringify(restThirdMenuList) + '}';
	var restMenuList = JSON.parse(temp);
	
	console.log("全部菜单减去组拥有菜单之后的列表" , restMenuList);
	getRestMenuListHtml(restMenuList);
};

//剩余菜单生成DOM的方法
function getRestMenuListHtml(list){
	//生成DOM
	newDom(list, '可添加权限', '#nestable2', 2);

};

function newDom(object, string, dom, type){
	var operaIcon = '';
	var operaSingleIcon = '';
	var menuIcon = '<span class="menu-icon fa fa-list" title="展开"></span>';
	if(type == 1){
		operaIcon = '<span class="menu-icon item-icon opera-icon opera-icon-delete fa fa-minus" title="删除(包括子项)"></span>';
	}else{
		operaIcon = '<span class="menu-icon item-icon opera-icon opera-icon-add fa fa-plus" title="新增(包括子项)"></span>';
		operaSingleIcon = '<span class="menu-icon item-icon opera-icon opera-icon-single opera-icon-delete-single fa fa-angle-left" title="新增(单项)"></span>';
	}
	var html = '<div class="nestable-title center" style="margin-bottom:20px;"><button class="btn btn-sm" type="button" disabled="disabled">' + string + '</button></div><ol class="dd-list">';
	$.each(object.firstMenu, function(index1, item1){
		html += '<li class="dd-item" data-parentid=' + item1.pcontrolid + ' data-id=' + item1.controlid + 
				'><div data-grade="1" class="dd-handle">' + item1.lname + 
				menuIcon + operaSingleIcon + operaIcon + '</div>';
		if(haschild(object.secondMenu, item1.controlid)){
			html += '<ol class="dd-list dd-list-grade-2 dd-list-flag setnone">';
			$.each(object.secondMenu, function(index2, item2){
				if(item2.pcontrolid == item1.controlid){
					html += '<li class="dd-item" data-parentid=' + item2.pcontrolid + ' data-id=' + item2.controlid +
							'><div data-grade="2" class="dd-handle">' + item2.lname + 
							menuIcon + operaSingleIcon + operaIcon + '</div></li>';
					if(haschild(object.thirdMenu, item2.controlid)){
						html += '<ol class="dd-list dd-list-grade-2 dd-list-flag setnone">';
						$.each(object.thirdMenu, function(index3, item3){
							if(item3.pcontrolid == item2.controlid){
								html += '<li class="dd-item" data-parentid=' + item3.pcontrolid + ' data-id=' + item3.controlid +
										'><div data-grade="3" class="dd-handle">' + item3.lname + 
										operaIcon + '</div></li>';
							};
							 
						});
						html += '</ol>'; 
					};	
				};
				 
			});
			html += '</ol>'; 
		};
		html += '</li>'; 
	});	
	html += '</ol>';

    //以object.firstMenu.length作为判断是否有数据的依据,如果没有数据,则插入dd-empty
	if(object.firstMenu.length == 0){
		$(dom).html('<div class="nestable-title center" style="margin-bottom:20px;"><button class="btn btn-sm" type="button" disabled="disabled">' + string + '</button></div>');
	}else{
		$(dom).html(html); 
	}	
};

//移动列表的请求方法
function getPostList(listString, type){
	//post comid,userid和权限菜单的controlid数组,发送请求
	$.ajax({
		"type": "POST",
		"dataType": 'json',
		"url": ctx + "/system/userofrole/changeAuth.action?type=" + type,
		"data": {"groupid":postGroupid, "menuList":listString, "creator": creator},
		"beforeSend": function(){
			$(".load_bg,.load_img").show();
		},
		"success": function(resp){
			console.log("增/删成功后返回的结果:" , resp);	
			//重新获取菜单
			getLimitedMenuList();
		},
		"error": function(XMLHttpRequest, textStatus, errorThrown) {
			alert(textStatus);
		},
		"complete": function(){
			$(".load_bg,.load_img").hide();
		}
	});
};

//去除菜单json的索引和list数组的值不相同的元素
function getNotSameJson(parentObj, childObj){
	var finalObj = [],
        controlid1 = '',
		controlid2 = '',
		count = 0;
	if(parentObj.length > 0){
		for(var i=0;i<parentObj.length;i++){
			controlid1 = parentObj[i].controlid;
			count = 0;
			if(parentObj.length > 0){
				for(var j=0;j<childObj.length;j++){
					controlid2 = childObj[j];
					if(controlid1 == controlid2){
						count++;
					}
				}
			}
			//表示数组1的这个值没有重复的，放到返回列表中
			if(count==0){
				finalObj.push(parentObj[i]);
			};
		}
	}
	
	return finalObj;
};

//去除两个list数组中不相同的元素
function getNotSameEle(arra, arrb){
	var str = '',
        stra = '',
		strb = '',
		count = 0;
	for(var i=0;i<arra.length;i++){
		stra = arra[i];
		count = 0;
		for(var j=0;j<arrb.length;j++){
			strb=arrb[j];
			if(stra == strb){
				count++;
			}
		}
		//表示数组1的这个值没有重复的，放到返回列表中
		if(count==0){
			str += '#' + stra;
		};
	}
	str = str.substring(1);
	return str;
};

//检查是否有子元素的方法
function haschild(list, id){
	var $haschild = false;
	$.each(list, function(index,item){
		if(item.pcontrolid == id){
			$haschild = true;
			return false;
		};
	});
	return $haschild;
};

//检查是否有元素的方法
function hasElement(list, id){
	var $haschild = false;
	$.each(list, function(index,item){
		if(item == id){
			$haschild = true;
			return false;
		};
	});
	return $haschild;
};
</script>
		
</body>
</html>